package com.cheer.dto;

import com.cheer.entity.Admin;
import com.cheer.entity.Organization;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author cheer
 */
@Data
@Accessors(chain = true)
public class AdminSaveDTO {

    @NotNull(message = "组织机构Id不能为空")
    private Long orgId;

    @NotBlank(message = "负责人不能为空")
    @Length(max = 20, message = "负责人不能超过20个字符")
    private String contactPerson;

    @NotBlank(message = "手机号不能为空")
    @Length(max = 20, message = "手机号不能超过20个字符")
    private String phone;

    @Length(max = 20, message = "备用账号不能超过20个字符")
    private String backupAccount;

    @Length(max = 20, message = "密码不能超过20个字符")
    private String password;

    @Length(max = 20, message = "确认密码不能超过20个字符")
    private String confirmPassword;

    public AccountDTO build(Integer role) {
        AccountDTO accountDTO = new AccountDTO();
        accountDTO.setPhone(phone);
        accountDTO.setBackupAccount(backupAccount);
        accountDTO.setPassword(password);
        accountDTO.setRole(role);
        accountDTO.setSecurityQuestion("管理员负责人叫什么？");
        accountDTO.setSecurityAnswer(contactPerson);
        return accountDTO;
    }

    public Admin build(Long accountId, Organization organization) {
        Admin admin = new Admin();
        admin.setAccountId(accountId);
        admin.setContactPerson(contactPerson);
        admin.setOrgId(organization.getId());
        admin.setOrgPath(organization.getOrgPath());
        return admin;
    }
}
